package com.salesmonitoring.accounts.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import org.jdesktop.swingx.JXDatePicker;

import com.salesmonitoring.accounts.controller.AdminController;
import com.salesmonitoring.accounts.model.User;
import com.salesmonitoring.model.RepairShop;

public class EditReportUI extends JFrame implements ActionListener {

	private JPanel editReportPanel;
	private JLabel lblAccountOfficer, lblOldCustName;
	private JComboBox accountOfficerComboBox;

	private ArrayList<User> users;
	private String[] names, shops;
	private JTextField oldCustNameTextField;
	private JLabel lblNewCustName;
	private JTextField newCustNameTextField;
	private JLabel lblDateRequested;
	private JXDatePicker dateRequestedPicker;
	private JLabel lblDateOfRepo;
	private JXDatePicker dateRepoPicker;
	private JLabel lblDateSold;
	private JXDatePicker dateSoldPicker;
	private JLabel lblRepairShop;
	private JComboBox repairShopComboBox;
	private JLabel lblRepairShopOwner;
	private JTextField repairShopOwnerTextField;
	private JLabel lblRepairShopAddress;
	private JTextField repairShopAddressTextField;
	private JLabel lblRepairShopWarehouse;
	private JTextField repairShopWarehouseTextField;
	private JLabel lblModel;
	private JTextField motorModelTextField;
	private JLabel lblEngine;
	private JTextField motorEngineTextField;
	private JLabel lblChassis;
	private JTextField motorChassisTextField;
	private JLabel lblPlateNumber;
	private JTextField motorPlateNumberTextField;
	private JLabel lblClass;
	private JTextField motorClassTextField;
	private JLabel lblWarehouse;
	private JComboBox motorWarehouseComboBox;
	private JButton addButton;
	private JButton saveButton;
	private JTextField accountNumbertextField;
	private JLabel lblAsmf_1;
	private JTextField asmfNumberTextField;

	public EditReportUI() {

		AdminController adminController = AdminController.getInstance();

		this.users = adminController.getAllUsers();
		this.names = adminController.getAllAONames();
		this.shops = adminController.getAllRepairShops();

		initComponents();
	}

	public void initComponents() {

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 625, 350);
		editReportPanel = new JPanel();
		editReportPanel.setLayout(null);
		setContentPane(editReportPanel);

		// ---Account officer combo box
		lblAccountOfficer = new JLabel("Account Officer");
		lblAccountOfficer.setBounds(15, 15, 137, 16);
		editReportPanel.add(lblAccountOfficer);

		accountOfficerComboBox = new JComboBox(names);
		accountOfficerComboBox.setBounds(164, 11, 157, 27);
		editReportPanel.add(accountOfficerComboBox);

		// ---Old cust name textfield
		lblOldCustName = new JLabel("Old Customer Name ");
		lblOldCustName.setBounds(15, 43, 157, 16);
		editReportPanel.add(lblOldCustName);

		oldCustNameTextField = new JTextField();
		oldCustNameTextField.setBounds(164, 39, 157, 28);
		oldCustNameTextField.setColumns(10);
		editReportPanel.add(oldCustNameTextField);

		// ---New customer name textfield
		lblNewCustName = new JLabel("New Customer Name");
		lblNewCustName.setBounds(15, 75, 137, 16);
		editReportPanel.add(lblNewCustName);

		newCustNameTextField = new JTextField();
		newCustNameTextField.setColumns(10);
		newCustNameTextField.setBounds(164, 69, 157, 28);
		editReportPanel.add(newCustNameTextField);

		// ---Date requested picker
		lblDateRequested = new JLabel("Date Requested");
		lblDateRequested.setBounds(15, 105, 137, 16);
		editReportPanel.add(lblDateRequested);

		dateRequestedPicker = new JXDatePicker();
		dateRequestedPicker.setDate(Calendar.getInstance().getTime());
		dateRequestedPicker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
		dateRequestedPicker.setBounds(164, 99, 157, 28);
		editReportPanel.add(dateRequestedPicker);

		// ---Date of repo picker
		lblDateOfRepo = new JLabel("Date of Repo");
		lblDateOfRepo.setBounds(15, 135, 137, 16);
		editReportPanel.add(lblDateOfRepo);

		dateRepoPicker = new JXDatePicker();
		dateRepoPicker.setDate(Calendar.getInstance().getTime());
		dateRepoPicker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
		dateRepoPicker.setBounds(164, 129, 157, 28);
		editReportPanel.add(dateRepoPicker);

		// ---Date sold picker
		lblDateSold = new JLabel("Date Sold");
		lblDateSold.setBounds(15, 165, 137, 16);
		editReportPanel.add(lblDateSold);

		dateSoldPicker = new JXDatePicker();
		dateSoldPicker.setDate(Calendar.getInstance().getTime());
		dateSoldPicker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
		dateSoldPicker.setBounds(164, 159, 157, 28);
		editReportPanel.add(dateSoldPicker);

		// --------------Repair Shop Details------------------//

		// ---Repair shop text field
		lblRepairShop = new JLabel("Repair Shop");
		lblRepairShop.setBounds(15, 195, 137, 16);
		editReportPanel.add(lblRepairShop);

		repairShopComboBox = new JComboBox(shops);
		repairShopComboBox.setBounds(164, 191, 157, 27);
		repairShopComboBox.addActionListener(new ActionListener() {

			private AbstractButton repairShopOwnerTextField;
			private AbstractButton repairShopAddressTextField;
			private AbstractButton repairShopWarehouseTextField;

			@Override
			public void actionPerformed(ActionEvent arg0) {

				AdminController adminController = AdminController.getInstance();
				RepairShop shop = adminController
						.getShopBycode(repairShopComboBox.getSelectedItem()
								.toString());

				repairShopOwnerTextField.setText(shop.getOwner());
				repairShopAddressTextField.setText(shop.getAddress());
				repairShopWarehouseTextField.setText(shop.getWarehouse());

			}
		});

		editReportPanel.add(repairShopComboBox);

		// ---Repair shop owner text field
		lblRepairShopOwner = new JLabel("Repair Shop Owner");
		lblRepairShopOwner.setBounds(15, 225, 137, 16);
		editReportPanel.add(lblRepairShopOwner);

		repairShopOwnerTextField = new JTextField();
		repairShopOwnerTextField.setColumns(10);
		repairShopOwnerTextField.setBounds(164, 219, 157, 28);
		repairShopOwnerTextField.setEditable(false);
		repairShopOwnerTextField.setText("Owner Name");
		editReportPanel.add(repairShopOwnerTextField);

		// ---Repair shop address textfield
		lblRepairShopAddress = new JLabel("Repair Shop Address");
		lblRepairShopAddress.setBounds(15, 255, 137, 16);
		editReportPanel.add(lblRepairShopAddress);

		repairShopAddressTextField = new JTextField();
		repairShopAddressTextField.setColumns(10);
		repairShopAddressTextField.setBounds(164, 249, 157, 28);
		repairShopAddressTextField.setEditable(false);
		repairShopAddressTextField.setText("Shop Address");
		editReportPanel.add(repairShopAddressTextField);

		// ---Repair shop warehouse combo box
		lblRepairShopWarehouse = new JLabel("Repair Shop Warehouse");
		lblRepairShopWarehouse.setBounds(15, 285, 157, 16);
		editReportPanel.add(lblRepairShopWarehouse);

		repairShopWarehouseTextField = new JTextField();
		repairShopWarehouseTextField.setBounds(164, 281, 157, 27);
		repairShopWarehouseTextField.setEditable(false);
		repairShopWarehouseTextField.setText("Warehouse Assigned");
		editReportPanel.add(repairShopWarehouseTextField);

		// --------------Motorcycle Details-------------------//

		// --- Motorcycle model textfield

		lblModel = new JLabel("Model");
		lblModel.setBounds(350, 15, 137, 16);
		editReportPanel.add(lblModel);

		motorModelTextField = new JTextField();
		motorModelTextField.setColumns(10);
		motorModelTextField.setBounds(456, 9, 157, 28);
		editReportPanel.add(motorModelTextField);

		// ---Motorcycle engine textfield
		lblEngine = new JLabel("Engine");
		lblEngine.setBounds(350, 45, 137, 16);
		editReportPanel.add(lblEngine);

		motorEngineTextField = new JTextField();
		motorEngineTextField.setColumns(10);
		motorEngineTextField.setBounds(456, 39, 157, 28);
		editReportPanel.add(motorEngineTextField);

		// --- Motorcycle chasis textfield

		lblChassis = new JLabel("Chassis");
		lblChassis.setBounds(350, 75, 137, 16);
		editReportPanel.add(lblChassis);

		motorChassisTextField = new JTextField();
		motorChassisTextField.setColumns(10);
		motorChassisTextField.setBounds(456, 69, 157, 28);
		editReportPanel.add(motorChassisTextField);

		// ---Motorcycle plate number textfield

		lblPlateNumber = new JLabel("Plate Number");
		lblPlateNumber.setBounds(350, 105, 137, 16);
		editReportPanel.add(lblPlateNumber);

		motorPlateNumberTextField = new JTextField();
		motorPlateNumberTextField.setColumns(10);
		motorPlateNumberTextField.setBounds(456, 99, 157, 28);
		editReportPanel.add(motorPlateNumberTextField);

		// ---Motorcycle class textfield

		lblClass = new JLabel("Class");
		lblClass.setBounds(350, 135, 137, 16);
		editReportPanel.add(lblClass);

		motorClassTextField = new JTextField();
		motorClassTextField.setColumns(10);
		motorClassTextField.setBounds(456, 129, 157, 28);
		editReportPanel.add(motorClassTextField);

		// ---Motorcycle warehouse textfield

		lblWarehouse = new JLabel("Warehouse");
		lblWarehouse.setBounds(350, 165, 137, 16);
		editReportPanel.add(lblWarehouse);

		motorWarehouseComboBox = new JComboBox();
		motorWarehouseComboBox.setBounds(456, 161, 157, 27);
		editReportPanel.add(motorWarehouseComboBox);

		saveButton = new JButton("Save");
		saveButton.setBounds(430, 259, 117, 29);
		saveButton.addActionListener(this);
		editReportPanel.add(saveButton);
		
		JLabel lblAccountNumber = new JLabel("Account #");
		lblAccountNumber.setBounds(350, 195, 137, 16);
		editReportPanel.add(lblAccountNumber);
		
		accountNumbertextField = new JTextField();
		accountNumbertextField.setBounds(456, 189, 157, 28);
		editReportPanel.add(accountNumbertextField);
		accountNumbertextField.setColumns(10);
		
		lblAsmf_1 = new JLabel("ASMF #");
		lblAsmf_1.setBounds(350, 225, 137, 16);
		editReportPanel.add(lblAsmf_1);
		
		asmfNumberTextField = new JTextField();
		asmfNumberTextField.setBounds(456, 219, 157, 28);
		editReportPanel.add(asmfNumberTextField);
		asmfNumberTextField.setColumns(10);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

	}
}
